<?php
class IndexAction extends MaterialAction
{
	public function _initialize() {
		parent::_initialize ();
		$this->assign('nav', 1);
	}

	public function index(){
		$allCount = D('Material')->count();
		$Page = $this->getPage($allCount);
		$list = D('Material')->getList(null,$Page->firstRow.','.$Page->listRows);
		foreach($list as $key=>$brand){
			$dirName = $this->_BASE_DIR.'/'.$brand['name'].'/news/';
			$dirName = auto_charset($dirName, 'utf-8', 'gbk');
			$count = 0;
			if(is_dir($dirName)){
				$handler = opendir($dirName);
				while( ($filename = readdir($handler)) !== false )
				{
					if($filename != "." && $filename != ".." && $filename != ".svn")
					{
						$count++;
					}
				}
			}
			$list[$key]['count'] = $count;
		}
		$this->assign('list', $list);
		$this->assign('page', $Page->show());
		$this->display();
	}

	public function dir(){
		$name = getGet('name');
		$this->assign('name', $name);
		$name = auto_charset($name, 'utf-8', 'gbk');
		$dirName = $this->_BASE_DIR.'/'.$name.'/news/';
		$list = array();
		if(is_dir($dirName)){
			$handler = opendir($dirName);
			while( ($filename = readdir($handler)) !== false )
			{
				if($filename != "." && $filename != ".." && $filename != ".svn")
				{
					$list[] = base64_encode($dirName.$filename);
				}
			}
		}
		$this->assign('list', $list);
		$this->display();
	}

	public function psdRead(){
		$uri = getGet('uri');
		if($uri){
			$uri = base64_decode($uri);
		}
		if(is_file($uri)){
			header("Content-type: image/jpeg");
			import ( "@.ORG.Util.PsdReader" );
			imagejpeg(imagecreatefrompsd($uri));
		}
	}
}
?>